I need to do repeated Cox analysis and have a set of codes to grab median and overall survival and several numbers that keep repeating over in a putdocx file for different binary variables with 1 being the worse outcome. I would like shorten the code by saving all options related to the numbers stored in a separate do file.
In the result analysis do file I have:
The main script for the results below in the do file:
The script of all options for the numbers in this nested survmasf.do file:
The code hangs with this below
How do I make the nested do file read the local macro defined in the main do file?
In the result analysis do file I have:
The main script for the results below in the do file:
Code:
local x myvar
do "C:\Users\Vijayalakshmi\Dropbox\Girish Files\Stata practice\survmasf.do"
putdocx text (" Patients lacking the myvar signature (n = `n0' [`p0'%]) had significantly superior median survival (`med0' months vs. `med1' months) and OS24 (`ms0_val' (vs. `ms1_val') compared those carrying the signature (HR= `b'; 95% CI= [`l'-`u'], p = `p') comprising (n = `n1' [`p1'%])")
drop ms0* ms1* _rc* _d_* tt med*
Code:
stcox ib0.`x' ib0.age70
matrix list r(table)
local b = round(r(table)[1,2], 0.01)
local l = round(r(table)[5,2], 0.01)
local u = round(r(table)[6,2], 0.01)
local p = round(r(table)[4,2], 0.0001)
local n = e(N)
****** Numbers in each group************
estpost tab `x'
mat list e(pct)
local p0 = string(round(e(pct)[1,1], 0.1))
local p1 = string(round(e(pct)[1,2], 0.1))
mat list e(b)
local n0 = e(b)[1,1]
local n1 = e(b)[1,2]
*Get Median and 24mo OS after adjusted analysis
range tt 1 24 24
qui stpm2 i.`x' i.age70, df(4) eform scale(h)
forval i=0/1{
predict ms`i', meansurv ci timevar(tt) at(`x' `i')
}
*Median survival
predict medsurv, centile(50)
summ medsurv if `x'==0, detail
local med0 = round(r(p50), 0.1)
summ medsurv if `x'==1, detail
local med1 = round(r(p50), 0.1)
*OS24
local ms0_val = string(round(ms0[24] * 100, 0.1), "%9.1f") + "%"
local ms1_val = string(round(ms1[24] * 100, 0.1), "%9.1f") + "%"
Code:
. stcox ib0.`x' ib0.age70 ib0.age70 invalid name r(198);

Comment